package net.hn.hnms.biz.process.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.process.domain.StartWorkPo;
import net.hn.hnms.biz.process.domain.vo.StartWorkDataVo;
import net.hn.hnms.biz.process.service.StartProcessService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import net.hn.hnms.biz.process.domain.dto.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 功能描述: 开工流程管理(零星工程)
 * @auther: WangLong
 * @date: 2022/7/18 11:02
 * @param
 * @return
 */

@Api(value = "开工流程管理控制器", tags = {"开工流程管理(零星工程)"})
@RestController
@RequestMapping("startProcess")
public class StartProcessController {
    @Resource
    private StartProcessService startProcessService;
    /**
     * 功能描述: 开工管理添加
     *
     * @param
     * @return net.hn.hnms.sys.common.core.domain.R
     * @auther: WangLong
     * @date: 2022/7/22 14:09
     */
    @ApiOperation("开工管理添加")
    @PostMapping("customization/add")
    @Log(title = "添加开工管理", businessType = BusinessType.INSERT)
    public R customizationAdd(@Validated @RequestBody StartWorkPo startWorkPo) {
        boolean save = startProcessService.customizationAdd(startWorkPo);
        if (save) {
            return R.ok("开工管理添加成功");
        }

        return R.fail("开工管理添加失败");
    }

    /**
     * 开工管理修改
     * @param startWorkPo
     * @return
     */
    @ApiOperation("开工管理修改")
    @PutMapping("customization/update")
    @Log(title = "修改开工管理", businessType = BusinessType.UPDATE)
    public R customizationUpdate(@Validated @RequestBody StartWorkPo startWorkPo) {
        boolean is = startProcessService.customizationUpdate(startWorkPo);
        if (is) {
            return R.ok("更新开工管理成功");
        }

        return R.fail("更新开工管理失败");
    }

    @ApiOperation("开工管理状态修改")
    @PutMapping("customization/amendStatus/{id}")
    @Log(title = "修改开工管理", businessType = BusinessType.UPDATE)
    public R amendStatusById(@PathVariable String id) {
        Boolean is = startProcessService.amendStatusById(id);
        if (is) {
            return R.ok("开工管理状态修改成功");
        }
        return R.fail("开工管理状态修改失败");
    }
    /**
     * 功能描述: 开工管理批量删除
     * @auther: WangLong
     * @date: 2022/7/22 14:10
     * @param
     * @return net.hn.hnms.sys.common.core.domain.R
     */
    @ApiOperation("开工管理批量删除")
    @DeleteMapping("customization/delete")
    @Log(title = "删除开工管理", businessType = BusinessType.DELETE)
    public R customizationDelete(@RequestBody List<String> idList) {
        boolean b = startProcessService.customizationDelete(idList);
        if (b) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }

    /**
     * 功能描述:分页条件查询开工管理列表
     *
     * @param
     * @return net.hn.hnms.sys.common.core.domain.R
     * @auther: WangLong
     * @date: 2022/7/22 14:06
     */

    @ApiOperation("分页条件查询开工管理列表")
    @GetMapping("customization/pageList")
    @AutoSetMineCode
    @Log(title = "查询开工管理", businessType = BusinessType.OTHER)
    public R<ResponsePage<StartWorkPo>> customizationPageList(PageQuery pageQuery,  StartWorkPo startWorkPo) {
        ResponsePage<StartWorkPo> page = startProcessService.customizationPageList(pageQuery,startWorkPo);
        return R.ok(page);
    }
    @ApiOperation("开工管理审批流程设置")
    @PostMapping("addApprove/add")
    @Log(title = "设置审批流程", businessType = BusinessType.UPDATE)
    public R addApproveAdd(@Validated @RequestBody StartWorkFlowDto startWorkFlowDto) {
        Boolean is = startProcessService.addApproveAdd(startWorkFlowDto);
        if (is) {

            return R.ok("添加审批成功");
        }
        return R.fail("添加审批失败");
    }

    @ApiOperation("开工管理审批流程修改")
    @PostMapping("addApprove/update")
    @Log(title = "修改审批流程", businessType = BusinessType.UPDATE)
    public R addApproveUpdate(@Validated @RequestBody StartWorkFlowDto startWorkFlowDto) {
        Boolean is = startProcessService.addApproveUpdate(startWorkFlowDto);
        if (is) {

            return R.ok("修改审批成功");
        }
        return R.fail("修改审批失败");
    }

    @ApiOperation("根据开工管理ID获取审批序号列表")
    @PutMapping("approve/{id}")
    @Log(title = "ID获取审批序号列表", businessType = BusinessType.OTHER)
    public R<StartWorkFlowDto> approveById(@PathVariable("id") String id) {

        StartWorkFlowDto startWorkFlowDto = startProcessService.approveById(id);
        return R.ok(startWorkFlowDto);
    }


    @ApiOperation("零星工程-添加")
    @PostMapping("project/add")
    @Log(title = "添加零星工程", businessType = BusinessType.INSERT)
    public R<StartWorkFlowDto> projectAdd(@RequestBody StartWorkDataDto startWorkDataDto) {

        Boolean is  = startProcessService.projectAdd(startWorkDataDto);
        if (is) {
            return R.ok("零星工程添加成功");
        }
        return R.fail("零星工程添加失败");
    }
    @ApiOperation("零星工程-分页条件查询")
    @GetMapping("project/pageList")
    @AutoSetMineCode
    @Log(title = "查询零星工程", businessType = BusinessType.OTHER)
    public R<ResponsePage<StartWorkDataVo>> projectPageList(PageQuery pageQuery, StartDataDto startWorkDataDto) {

        ResponsePage<StartWorkDataVo> page = startProcessService.projectPageList(pageQuery, startWorkDataDto);
        return R.ok(page);
    }
    @ApiOperation("完成审批")
    @GetMapping("accomplishApprove")
    @Log(title = "修改零星工程", businessType = BusinessType.UPDATE)
    public R accomplishApprove(@ApiParam(value = "请输入审批工作票ID") @RequestParam(value = "businessKey") String businessKey,
                               @ApiParam(value = "是否需要登录人审批，默认为true") @RequestParam(value = "is", required = false, defaultValue = "true") Boolean is,
                               @ApiParam(value = "是否同意审批，1同意，0拒绝") @RequestParam(value = "approve") String approve,
                               @ApiParam(value = "审批意见内容") @RequestParam(value = "content") String content) {
        Boolean aBooleanis = startProcessService.accomplishApprove(businessKey, is,approve,content);

        return R.ok(aBooleanis);
    }
    /**
     * 功能描述: 撤销审批
     *
     * @param id
     * @return net.hn.hnms.sys.common.core.domain.R
     * @auther: WangLong
     * @date: 2022/8/11 17:34
     */

    @ApiOperation("撤销审批")
    @PutMapping("revocationApprove/{id}")
    @Log(title = "修改零星工程", businessType = BusinessType.UPDATE)
    public R revocationApproveById(@PathVariable("id") String id) {

        Boolean is = startProcessService.revocationApproveById(id);
        if (is) {
            return R.ok("撤销成功");
        }
        return R.fail("撤销失败");
    }
    @ApiOperation("获取我的审批列表")
    @GetMapping("myApprove/pageList")
    @AutoSetMineCode
    @Log(title = "查询我的审批列表", businessType = BusinessType.OTHER)
    public R<List<StartWorkDataVo>> myApprove(@ApiParam(value = "煤矿编码") String mineCode) {

        List<StartWorkDataVo> page = startProcessService.myApprove(mineCode);
        return R.ok(page);
    }


    /**
     * 功能描述: 根据零星工程DataID获取审批序号列表
     *
     * @param id
     * @return net.hn.hnms.sys.common.core.domain.R
     * @auther: WangLong
     * @date: 2022/8/11 17:34
     */

    @ApiOperation("根据零星工程DataID获取审批序号列表")
    @GetMapping("approveData/{id}")
    @Log(title = "DataID获取审批序号列表", businessType = BusinessType.OTHER)
    public R<StartFlowDataDto> approveDataById(@PathVariable("id") String id) {

        StartFlowDataDto startFlowDataDto = startProcessService.approveDataById(id);
        return R.ok(startFlowDataDto);
    }
    @ApiOperation("零星工程-批量删除")
    @DeleteMapping("project/delete")
    @Log(title = "删除零星工程", businessType = BusinessType.DELETE)
    public R projectDelete(@RequestBody List<String> idList) {
        Boolean is = startProcessService.projectDelete(idList);
        if (is) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
    @ApiOperation("零星工程-From表单修改")
    @PutMapping("from/update")
    @Log(title = "修改零星工程FORM表单", businessType = BusinessType.UPDATE)
    public R fromUpdate(@RequestBody FromUpdateDto fromUpdateDto) {

        Boolean is = startProcessService.fromUpdate(fromUpdateDto);
        if (is) {

            return R.ok("修改表单成功");
        }
        return R.fail("修改表单失败");
    }
}
